package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.domain.LoaiDanhMuc;
import com.tt.fashionWebSite.dto.*;
import com.tt.fashionWebSite.service.Ad_ProductSizeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

@Controller
public class Ad_ProductSizeController {
    @Autowired
    private Ad_ProductSizeService ad_productSizeService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/registerProductSize", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminProductSize(HttpServletRequest request, @RequestBody KichThuocDto productSizeDto) {
        return new JsonResponseDto<Integer>(ad_productSizeService.adminProductSize(productSizeDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/registerProductSizeDelete", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminProductSizeDelete(HttpServletRequest request, @RequestBody List<KichThuocDto> productSizeDto) {
        return new JsonResponseDto<Integer>(ad_productSizeService.adminProductSizeDelete(productSizeDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllCategoryInProductSizeCommon", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<LoaiDanhMucDto>> getAllListCategoryCommon(HttpServletRequest request) {
        return new JsonResponseDto<List<LoaiDanhMucDto>>(ad_productSizeService.getAllListCategoryCommon(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllCategoryInProductSize", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<LoaiDanhMucDto>> getAllListCategory(HttpServletRequest request) {
        return new JsonResponseDto<List<LoaiDanhMucDto>>(ad_productSizeService.getAllListCategory(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllSize", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<KichThuocDto>> getAllSize(HttpServletRequest request) {
        return new JsonResponseDto<List<KichThuocDto>>(ad_productSizeService.getAllSize(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toProductSizePage/{maSize}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageProductSize(HttpServletRequest request, @PathVariable String maSize, Map<String, Object> map) throws ParseException {
        map.put("maSize", maSize);
        return new ModelAndView("admin/ad-product-size-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editProductSize", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<KichThuocDto> getSizeInfoEdit(HttpServletRequest request, @RequestBody KichThuocDto sizeDto) {
        return new JsonResponseDto<KichThuocDto>(ad_productSizeService.getSizeInfoEdit(sizeDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerSizeEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<KichThuocDto> registerSizeEdit(HttpServletRequest request, @RequestBody KichThuocDto sizeDto) {
        return new JsonResponseDto<KichThuocDto>(ad_productSizeService.registerSizeEdit(sizeDto), JsonResponseCode.SUCCESS);
    }
}
